package com.jiangyg.mall.coupon.controller;

import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.coupon.dto.SeckillSessionDTO;
import com.jiangyg.mall.coupon.service.SeckillSessionService;
import com.jiangyg.mall.coupon.vo.SeckillSessionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：秒杀活动场次控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-18 21:33:05
 */
@RestController
@RequestMapping("/coupon/seckill/session")
public class SeckillSessionController {

    /**
     * 秒杀活动场次接口
     */
    private final SeckillSessionService seckillSessionService;

    @Autowired
    public SeckillSessionController(SeckillSessionService seckillSessionService) {
        this.seckillSessionService = seckillSessionService;
    }

    /**
     * 功能描述：保存或者修改秒杀活动场次
     *
     * @param request 请求
     * @param dto     秒杀活动场次
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated SeckillSessionDTO dto) throws Exception {
        return Result.saveOrUpdate(seckillSessionService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取秒杀活动场次
     *
     * @param request          请求
     * @param seckillSessionId 秒杀活动场次ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<SeckillSessionVO> info(HttpServletRequest request, @RequestParam(name = "seckillSessionId") Long seckillSessionId) throws Exception {
        return Result.ok(seckillSessionService.selectById(seckillSessionId));
    }

    /**
     * 功能描述：删除秒杀活动场次
     *
     * @param request           请求
     * @param seckillSessionIds 批量删除的秒杀活动场次ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestBody List<Long> seckillSessionIds) {
        return Result.delete(seckillSessionService.delete(seckillSessionIds));
    }

}
